package doyouknow.group.CnAndZhb.controller;

import com.fasterxml.jackson.databind.ser.Serializers;
import doyouknow.group.CnAndZhb.entity.TbAdminConfig;
import doyouknow.group.CnAndZhb.entity.TbHotelInfo;
import doyouknow.group.CnAndZhb.error.BusinessException;
import doyouknow.group.CnAndZhb.error.EnumBusinessError;
import doyouknow.group.CnAndZhb.response.BaseControllerReturn;
import doyouknow.group.CnAndZhb.service.TbHotelInfoService;
import doyouknow.group.CnAndZhb.utils.SerializedField;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * (TbHotelInfo)表控制层
 *
 * @author cn
 * @since 2020-11-03 21:05:02
 */
@CrossOrigin
@RestController
@RequestMapping("tbHotelInfo")
public class TbHotelInfoController extends BaseController{
    /**
     * 服务对象
     */
    @Resource
    private TbHotelInfoService tbHotelInfoService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    public TbHotelInfo selectOne(Integer id) {
        return this.tbHotelInfoService.queryById(id);
    }


    @GetMapping("getHotelNamesByAdminId")
    @SerializedField(includes = "hotelName")
    public Object getHotelNameByAdminId(Integer AdminId){

        List<TbHotelInfo> tbHotelInfos= tbHotelInfoService.getHotelNamesByAdminId(AdminId);
        return BaseControllerReturn.create(tbHotelInfos,null);
    }

    @GetMapping("getHotelNamesByAdminPhoneNum")
    @SerializedField(includes = "hotelName")
    public Object getHotelNamesByAdminPhoneNum(String PhoneNum){
        List<TbHotelInfo> tbHotelInfos = tbHotelInfoService.getHotelNamesByPhoneNum(PhoneNum);
        return BaseControllerReturn.create(tbHotelInfos,null);
    }

    @GetMapping("getHotelNamesByAccount")
    @SerializedField(includes ={"id","hotelName"})
    public Object getHotelNamesByAccount(String Account) throws BusinessException{

        //入参校验
        if (StringUtils.isEmpty(Account)) {
            throw new BusinessException(EnumBusinessError.PARAMETER_VALIDATION_ERROR,"请输入正确的用户名或密码");
        }

        String accountValue = tbHotelInfoService.analyseAccount(Account);
        List<TbHotelInfo> tbHotelInfos = tbHotelInfoService.getHotelNamesByPhoneNum(accountValue);
        return BaseControllerReturn.create(tbHotelInfos,null);
    }


}